package com.bishe.tax.controller.sys;

import java.util.List;

import com.bishe.tax.entity.IndexPicture;
import com.bishe.tax.service.IndexPictureService;
import com.bishe.tax.utils.AjaxResult;
import com.bishe.tax.utils.TableDataInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.activiti.engine.identity.Picture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 首页图片 信息操作处理
 *
 * @author ruoyi
 * @date 2019-06-23
 */
@Controller
@RequestMapping("/system/picture")
public class IndexPictureController {
    private String prefix = "picture";

    @Autowired
    private IndexPictureService pictureService;

    @GetMapping("list")
    public String picture() {
        return prefix + "/list";
    }

    /**
     * 查询首页图片列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IndexPicture picture, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        List<IndexPicture> list = pictureService.selectPictureList(picture);
        return TableDataInfo.returnDataTable(new PageInfo<>(list).getTotal(), list);
    }


    /**
     * 新增首页图片
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存首页图片
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IndexPicture picture) {
        return AjaxResult.success(pictureService.insertPicture(picture));
    }

    /**
     * 修改首页图片
     */
    @GetMapping("/edit/{pictureId}")
    public String edit(@PathVariable("pictureId") Integer pictureId, ModelMap mmap) {
        IndexPicture picture = pictureService.selectPictureById(pictureId);
        mmap.put("picture", picture);
        return prefix + "/edit";
    }

    /**
     * 修改保存首页图片
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IndexPicture picture) {
        return AjaxResult.success(pictureService.updatePicture(picture));
    }

    /**
     * 删除首页图片
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return AjaxResult.success(pictureService.deletePictureByIds(ids));
    }

}
